from django.db import models

from User.models import SiteUser


class FileMeta(models.Model):
    file_description = models.TextField(null=True, blank=True)
    user = models.ForeignKey(SiteUser, null=False, blank=False, on_delete=models.CASCADE)  # 上传用户


class FileModel(models.Model):
    filename = models.CharField(max_length=255)  # 文件本身的名称 用于获取后缀名
    file = models.FileField(upload_to='uploads/')
    file_mapper = models.ForeignKey('self', null=True, blank=True, on_delete=models.SET_NULL)  # 自关联字段
    block_order = models.IntegerField(default=0)
    md5 = models.CharField(max_length=255, null=True)  # 文件md5值


class BlockFileModel(models.Model):
    files = models.TextField(null=False, blank=False)
    show_filename = models.CharField(max_length=255, null=False, blank=False)
    file_meta = models.OneToOneField(FileMeta, on_delete=models.CASCADE, null=True, blank=True)
    create_time = models.DateTimeField(auto_now_add=True, blank=True)
